package com.system.boot.rbac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.system.api.rbac.entity.bo.RoleComPanyBo;
import com.system.api.rbac.entity.po.SysRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 角色
 *
 * @author: lslands
 * @description:
 * @version：v1.0
 * @date: 2024/6/2 18:39
 */
@Mapper
public interface RoleMapper extends BaseMapper<SysRole> {

    /**
     * 查询角色编码是否重复
     * @param companyId 企业ID
     * @param code 角色编码
     * @return boolean
     * @author lslands
     * @date 2024/5/16 00:39
     */
    @Select("SELECT EXISTS(SELECT 1 FROM sys_role WHERE company_id=#{companyId} OR company_id=0 AND `code`=#{code})")
    boolean getExistsByCode(Long companyId,String code);


    /**
     * 查询角色名称是否重复
     * @param companyId 企业ID
     * @param name 角色名称
     * @return boolean
     * @author lslands
     * @date 2024/5/16 00:39
     */
    @Select("SELECT EXISTS(SELECT 1 FROM sys_role WHERE company_id=#{companyId} OR company_id=0 AND `name`=#{name})")
    boolean getExistsByName(Long companyId,String name);


    /**
     * 查询角色-企业关联数据
     * @return List<RoleComPanyBo>
     */
    List<RoleComPanyBo> selectRoleCompany();

    /**
     * 批量删除(物理)
     * @param ids ids集 | [1,2,3,4,5]
     * @return int
     */
    int deleteBatch(@Param("ids") List<Long> ids);
}
